<template>
  <div class="album">
    <!-- 照片墙 -->
    <div class="head">
      <div class="top">
        <div class="left" @click="goBack">
          <van-icon name="arrow-left" />
          <div class="title">专辑</div>
        </div>

        <div class="right" @click="showShare = true">
          <van-icon name="share-o" />
        </div>

        <!-- 分享面板 -->
        <van-share-sheet
          v-model="showShare"
          title="立即分享给好友"
          :options="options"
        />
      </div>

      <div class="headbox">
        <!-- 封图 -->
        <div class="map">
          <van-image :src="albumData.blurPicUrl" lazy-load>
            <template v-slot:loading>
              <van-loading type="spinner" size="20" />
            </template>
          </van-image>
        </div>

        <div class="text">
          <div class="songname">{{ albumData.name }}</div>
          <div class="songername">
            歌手：{{ albumartistData.name }} <van-icon name="arrow" />
          </div>

          <div class="time">
            发行时间：{{ albumData.publishTime | formatDate }}
          </div>
          <div class="tit" @click="showPopup">
            <div class="brief">
              {{ albumData.description }}
            </div>

            <van-icon name="arrow" />
          </div>
        </div>

        <!-- 专辑简介 -->
        <van-popup v-model="show">
          <div class="briefbox">
            <div class="photo">
              <van-image :src="albumData.blurPicUrl" lazy-load>
                <template v-slot:loading>
                  <van-loading type="spinner" size="20" />
                </template>
              </van-image>
            </div>
            <div class="briefname">{{ albumData.name }}</div>

            <div class="company">发行公司：{{ albumData.company }}</div>
            <div class="category">专辑类别：{{ albumData.subType }}</div>
            <div class="brieftext">{{ albumData.description }}</div>
          </div>
        </van-popup>
      </div>
    </div>

    <!-- 功能栏 -->
    <div class="function">
      <div class="list">
        <van-icon name="add-o" />{{ dynamicData.subCount | playvolume }}
      </div>
      <div class="list" @click="commentshow = true">
        <van-icon name="comment-o" />{{ dynamicData.commentCount | playvolume }}
      </div>
    </div>

    <!-- 评论列表 -->
    <div class="comment">
      <van-popup
        v-model="commentshow"
        round
        position="bottom"
        :style="{ height: '80%' }"
      >
        <div class="commenttitle">精彩评论</div>

        <div class="commentmain">
          <div
            class="commentlist"
            v-for="(item, index) in commentData"
            :key="index"
          >
            <div class="listhead">
              <van-image
                width="50"
                height="50"
                round
                lazy-load
                :src="item.user.avatarUrl"
              >
                <template v-slot:loading>
                  <van-loading type="spinner" size="20" />
                </template>
              </van-image>
            </div>

            <div class="listtext">
              <div class="listtextbox">
                <div class="txtbox">
                  <div class="user">{{ item.user.nickname }}</div>
                  <div class="commenttime">{{ item.time | formatDate }}</div>
                </div>

                <div class="like">
                  <div class="liketxt">{{item.likedCount}}</div>
                  <van-icon name="flower-o" />
                </div>
              </div>

              <div class="commenttext">{{ item.content }}</div>
            </div>
          </div>
        </div>
      </van-popup>
    </div>

    <!-- 歌曲列表 -->
    <div class="songslist">
      <div
        class="listbox"
        v-for="(item, index) in albumsongsData"
        :key="index"
        @click="playAudio(item.id, item.al.picUrl)"
      >
        <div class="no">{{ item.no }}</div>

        <div class="tabname">
          <div class="tabsongname">{{ item.name }}</div>
          <div class="tabtxt">
            <div class="textbox">SQ</div>
            {{ item.ar[0].name }}
          </div>
        </div>

        <div class="play">
          <van-icon
            :name="
              audioId !== item.id
                ? 'play-circle-o'
                : isPaused
                ? 'play-circle-o'
                : 'pause-circle-o'
            "
          />
        </div>

        <div class="share">
          <van-icon name="ellipsis" />
        </div>
      </div>
    </div>

    <!-- 播放器 -->
    <Playbox></Playbox>
  </div>
</template>

<script>
import Playbox from "../components/Playbox.vue";
import { mapState, mapMutations } from "vuex";
export default {
  name: "Album",

  components: {
    Playbox,
  },

  data() {
    return {
      show: false,

      // 分享面板
      showShare: false,
      options: [
        [
          { name: "微信", icon: "wechat" },
          { name: "朋友圈", icon: "wechat-moments" },
          { name: "微博", icon: "weibo" },
          { name: "QQ", icon: "qq" },
        ],
        [
          { name: "复制链接", icon: "link" },
          { name: "分享海报", icon: "poster" },
          { name: "二维码", icon: "qrcode" },
          { name: "小程序码", icon: "weapp-qrcode" },
        ],
      ],

      //专辑id
      id: "",

      // 专辑数据
      albumData: [],
      albumartistData: [],

      // 专辑歌曲数据
      albumsongsData: [],

      //专辑动态信息数据
      dynamicData: [],

      //专辑评论数据
      commentData: [],
      commentshow: false,
    };
  },

  created() {
    this.id = this.$route.params.id;

    //获取专辑数据
    this.getAlbum();

    //获取专辑动态信息
    this.getDynamic();

    //获取专辑评论数据
    this.getComment();
  },

  computed: {
    ...mapState(["audioId", "audioEle", "isPaused"]),
  },

  methods: {
    //返回上一级
    goBack() {
      this.$router.go(-1);
    },

    showPopup() {
      this.show = true;
    },

    //获取专辑数据
    getAlbum() {
      this.axios({
        method: "get",
        url: "/album",
        params: {
          id: this.id,
        },
      })
        .then((res) => {
          this.albumData = res.data.album;
          this.albumartistData = this.albumData.artist;
          this.albumsongsData = res.data.songs;
        })
        .catch((err) => {
          
        });
    },

    //获取专辑动态信息
    getDynamic() {
      this.axios({
        method: "get",
        url: "/album/detail/dynamic",
        params: {
          id: this.id,
        },
      })
        .then((res) => {
          this.dynamicData = res.data;
        })
        .catch((err) => {
          
        });
    },

    //获取专辑评论数据
    getComment() {
      this.axios({
        method: "get",
        url: "/comment/album",
        params: {
          id: this.id,
        },
      })
        .then((res) => {
          this.commentData = res.data.hotComments;
        })
        .catch((err) => {
          
        });
    },

    ...mapMutations(["changeStateProperty"]),

    // 点击播放音频
    playAudio(id, picUrl) {
      if (id === this.audioId) {
        if (!this.audioEle.paused) {
          //暂停歌曲
          this.audioEle.pause();
          this.changeStateProperty({ key: "isPaused", value: true });
        } else {
          //播放歌曲
          this.audioEle.play();
          this.changeStateProperty({ key: "isPaused", value: false });
        }
        return;
      }

      //获取音频url
      this.axios({
        method: "get",
        url: "/song/url",
        params: {
          id,
        },
      })
        .then((res) => {
          let audioUrl = res.data.data[0].url;
          this.changeStateProperty({ key: "audioUrl", value: audioUrl });
          this.changeStateProperty({ key: "audioId", value: id });
          //获取暂停状态
          this.changeStateProperty({ key: "isPaused", value: false });
        })
        .catch((err) => {
          
        });

      //获取播放图片
      this.changeStateProperty({ key: "picUrl", value: picUrl });
    },
  },
};
</script>

<style lang="less" scoped>
// 照片墙
.head {
  width: 100%;
  height: 170px;
  padding-bottom: 30px;
  display: flex;
  flex-wrap: wrap;
  background-color: #321a0f;
}

.top {
  width: 100%;
  display: flex;
  padding: 10px 20px;
}

.left {
  height: 20px;
  font-size: 20px;
  color: #fff;
  display: flex;
}

.title {
  width: 50px;
  font-size: 16px;
  padding-left: 10px;
}

.right {
  width: 20px;
  height: 20px;
  font-size: 20px;
  margin-left: auto;
  color: #fff;
}

.headbox {
  width: 90%;
  padding: 10px;
  display: flex;
  margin: auto;
  &/deep/.van-popup {
    background-color: #3d2418ad;
    border-radius: 10px;
    width: 80%;
    padding: 10px 20px;
  }
}

.map {
  width: 90px;
  height: 90px;
  border-radius: 10px;
}

.map {
  &/deep/ .van-image__img {
    width: 90px;
    height: 90px;
    border-radius: 10px;
  }
  &/deep/.van-icon {
    left: 40px;
    top: 20px;
  }
}

.text {
  width: 80%;
  display: flex;
  flex-wrap: wrap;
  margin-left: 20px;
}

.songname {
  width: 100%;
  font-size: 14px;
  font-weight: 600;
  padding-bottom: 6px;
  color: #fff;
}

.songername {
  width: 100%;
  font-size: 12px;
  color: #c2bab7;
  padding-bottom: 10px;
}

.time {
  width: 100%;
  color: #8a7973;
}

.tit {
  width: 100%;
  color: #8a7973;
  display: flex;
  &/deep/.van-icon {
    top: 2px;
    left: 4px;
  }
}

.brief {
  width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

//功能栏
.function {
  width: 60%;
  border-radius: 20px;
  background-color: #fff;
  display: flex;
  margin: auto;
  padding: 10px 20px;
  margin-top: -20px;
}

.list {
  width: calc(100% / 2);
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-right: 1px solid #dadada;
  &:nth-child(2) {
    border: 0;
  }
  &/deep/.van-icon {
    font-size: 18px;
    padding-right: 6px;
    top: 2px;
  }
}

// 歌曲列表
.songslixt {
  width: 80%;
  margin: auto;
}

.listbox {
  width: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  margin-top: 10px;
  align-items: center;
}

.no {
  font-size: 14px;
  color: #9f9f9f;
  padding-left: 6px;
}

.tabname {
  width: 54%;
  display: flex;
  flex-wrap: wrap;
  padding-left: 6px;
}

.tabsongname {
  width: 100%;
  font-size: 14px;
  font-weight: 600;
  padding-left: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabtxt {
  display: flex;
  color: #9f9f9f;
  align-items: center;
}

.textbox {
  width: 30px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border: 1px solid red;
  color: red;
  transform: scale(0.5);
}

.play {
  width: 20px;
  height: 20px;
  font-size: 20px;
  color: #9f9f9f;
  margin-left: 90px;
}

.share {
  width: 20px;
  height: 20px;
  font-size: 20px;
  color: #9f9f9f;
  margin-left: auto;
}

// 专辑简介
.briefbox {
  width: 100%;
  height: 500px;
  display: flex;
  flex-wrap: wrap;
}

.photo {
  width: 150px;
  height: 150px;
  border-radius: 10px;
  margin: auto;
}

.photo {
  &/deep/ .van-image {
    width: 150px;
    height: 150px;
    border-radius: 10px;
  }
}

.briefname {
  width: 100%;
  padding: 16px 0 20px 0;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.company,
.category {
  width: 100%;
  color: #fff;
}

.brieftext {
  margin-top: 10px;
  color: #fff;
  padding-bottom: 20px;
}

// 评论列表
.commenttitle {
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  padding: 10px 20px;
  box-sizing: border-box;
  position: fixed;
  background-color: #fff;
  z-index: 99;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
}

.commentmain {
  margin-top: 40px;
}

.commentlist {
  width: 100%;
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 10px 14px;
  border-bottom: 1px solid #9f9f9f3a;
}

.listhead {
  width: 50px;
}

.listtext {
  width: 82%;
}

.listtextbox {
  display: flex;
  align-items: center;
}

.like {
  font-size: 20px;
  margin-left: auto;
  display: flex;
  align-items: center;
}

.liketxt {
  font-size: 12px;
  color: #9f9f9f;
}

.commenttext {
  width: 100%;
  padding-top: 6px;
  font-size: 14px;
}
</style>